/**
 * @(#)Metrics.java, 2008-5-7.
 * Copyright 2008  Program Analysis Research Group(PARG),Institute of Software, Peking University.
 * All rights reserved.
 */
package edu.pku.sei.pgie.analyzer.internal;

/**
 *
 * @author HeLi
 *
 */
public class Metrics {
    public enum MetricsEnum {
        ANVPC,
        ANVCIPC,
        ANVRIPC,
        ANMHDPC,
        ANMBDPC,
        ANSPM,
        ANMPC
    }

    /**
     * average number of variables per class
     */
    protected double ANVPC;

    /**
     * average number of variables for composite instances per class
     */
    protected double ANVCIPC;

    /**
     * average number of variables for referenced instances per class
     */
    protected double ANVRIPC;

    /**
     * average number of methods with head dependancies per class
     */
    protected double ANMHDPC;

    /**
     * average number of methods with body dependancies per class
     */
    protected double ANMBDPC;

    /**
     * average number of statements per method
     */
    protected double ANSPM;

    /**
     * average number of methods per class
     */
    protected double ANMPC;

    public double get(MetricsEnum me) {
        if (me == MetricsEnum.ANMBDPC) {
            return ANMBDPC;
        } else if (me == MetricsEnum.ANMHDPC) {
            return ANMHDPC;
        } else if (me == MetricsEnum.ANSPM) {
            return ANSPM;
        } else if (me == MetricsEnum.ANVCIPC) {
            return ANVCIPC;
        } else if (me == MetricsEnum.ANVPC) {
            return ANVPC;
        } else if(me == MetricsEnum.ANVRIPC) {
            return ANVRIPC;
        } else if(me == MetricsEnum.ANMPC) {
            return ANMPC;
        }
        throw new RuntimeException("satan");
    }

    public void modify(MetricsEnum me, double delta) {
        if (me == MetricsEnum.ANMBDPC) {
            ANMBDPC += delta;
        } else if (me == MetricsEnum.ANMHDPC) {
            ANMHDPC += delta;
        } else if (me == MetricsEnum.ANSPM) {
            ANSPM += delta;
        } else if (me == MetricsEnum.ANVCIPC) {
            ANVCIPC += delta;
        } else if (me == MetricsEnum.ANVPC) {
            ANVPC += delta;
        } else if (me == MetricsEnum.ANVRIPC) {
            ANVRIPC += delta;
        } else if (me == MetricsEnum.ANMPC) {
            ANMPC += delta;
        }
    }

    public void set(MetricsEnum me, double value) {
        if (me == MetricsEnum.ANMBDPC) {
            ANMBDPC = value;
        } else if (me == MetricsEnum.ANMHDPC) {
            ANMHDPC = value;
        } else if (me == MetricsEnum.ANSPM) {
            ANSPM = value;
        } else if (me == MetricsEnum.ANVCIPC) {
            ANVCIPC = value;
        } else if (me == MetricsEnum.ANVPC) {
            ANVPC = value;
        } else if (me == MetricsEnum.ANVRIPC) {
            ANVRIPC = value;
        } else if (me == MetricsEnum.ANMPC) {
            ANMPC = value;
        }
    }

    public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append(MetricsEnum.ANMBDPC+"="+ANMBDPC).append(";");
        buffer.append(MetricsEnum.ANMHDPC+"="+ANMHDPC).append(";");
        buffer.append(MetricsEnum.ANSPM+"="+ANSPM).append(";");
        buffer.append(MetricsEnum.ANVCIPC+"="+ANVCIPC).append(";");
        buffer.append(MetricsEnum.ANVPC+"="+ANVPC).append(";");
        buffer.append(MetricsEnum.ANVRIPC+"="+ANVRIPC).append(";");
        buffer.append(MetricsEnum.ANMPC+"="+ANMPC);
        return buffer.toString();
    }

    public static Metrics parse(String context) {
        Metrics metrics = new Metrics();
        String[] splits =context.split(";");
        for(String split : splits) {
            String[] pair = split.split("=");
            for(MetricsEnum v : MetricsEnum.values()) {
                if(v.toString().equals(pair[0]))
                    metrics.set(v, Double.parseDouble(pair[1]));
            }
        }
        return metrics;
    }

    public double getANMBDPC() {
        return ANMBDPC;
    }

    public void setANMBDPC(double anmbdpc) {
        ANMBDPC = anmbdpc;
    }

    public double getANMHDPC() {
        return ANMHDPC;
    }

    public void setANMHDPC(double anmhdpc) {
        ANMHDPC = anmhdpc;
    }

    public double getANSPM() {
        return ANSPM;
    }

    public void setANSPM(double anspm) {
        ANSPM = anspm;
    }

    public double getANVCIPC() {
        return ANVCIPC;
    }

    public void setANVCIPC(double anvcipc) {
        ANVCIPC = anvcipc;
    }

    public double getANVPC() {
        return ANVPC;
    }

    public void setANVPC(double anvpc) {
        ANVPC = anvpc;
    }

    public double getANVRIPC() {
        return ANVRIPC;
    }

    public void setANVRIPC(double anvripc) {
        ANVRIPC = anvripc;
    }

    public double getANMPC() {
        return ANMPC;
    }

    public void setANMPC(double anmpc) {
        ANMPC = anmpc;
    }
}
